package com.cloud.bc.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.cloud.bc.model.domain.UserInfo;
import com.cloud.bc.model.entity.BcAbouts;
import com.cloud.bc.model.entity.BcFeedbacks;
import com.cloud.bc.model.enums.CookieConst;
import com.cloud.bc.model.response.AjaxResp;
import com.cloud.common.util.CookieUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("m")
public class MUserController extends BaseController {

    /**
     * 注册
     */
    @GetMapping("register")
    public ModelAndView register(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "注册", "m/register");
        String openid = request.getParameter("openid");
        view.addObject("openid", openid);
        view.addObject("title", StrUtil.isEmpty(openid) ? "注册" : "绑定账号");
        return view;
    }

    /**
     * 登录
     */
    @GetMapping("login")
    public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = baseView(request, "登录", "m/login");
        String openid = request.getParameter("openid");
        view.addObject("openid", openid);
        view.addObject("title", StrUtil.isEmpty(openid) ? "登录" : "绑定账号");
        return view;
    }

    /**
     * 退出
     */
    @GetMapping("logout")
    public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) {
        CookieUtils.deleteCookie(request, response, CookieConst.loginCookie);
        String source = request.getParameter("source");
        if (StrUtil.isNotEmpty(source) && source.equals("pc")){
            return new ModelAndView("redirect:/");
        }
        return new ModelAndView("redirect:/m");
    }

    /**
     * 意见反馈
     */
    @GetMapping("feedback")
    public ModelAndView feedback(HttpServletRequest request) {
        BcAbouts bcAbouts = new BcAbouts();
        ModelAndView view = baseView(request, "意见反馈", "m/feedback");
        return view;
    }

}
